Skip to content

Run as background service: --tray, --install-autostart#9

Draft
PrEvIeS wants to merge 1 commit intoezbooz:mainfrom
PrEvIeS:upstream-pr/background-launcher
Draft

Run as background service: --tray, --install-autostart#9
PrEvIeS wants to merge 1 commit intoezbooz:mainfrom
PrEvIeS:upstream-pr/background-launcher

Conversation

@PrEvIeS
Copy link
Copy Markdown

@PrEvIeS PrEvIeS commented May 5, 2026

Summary

Closes the "Launch as background service when game starts" item in the README to-do list. Adds three new CLI flags to main.py so users can run the RPC as a Windows tray service that auto-starts on login.

pip install pystray Pillow pylnk3
python main.py --tray              # foreground tray icon
python main.py --install-autostart # boot --tray on Windows login
python main.py --uninstall-autostart

The tray menu exposes Status (waiting / running / error), Open log file, Restart, and Quit. Quitting drains the watcher cleanly via a threading.Event.

What changed

File Diff
main.py +179 / -3
requirements.txt +4 / -0 (comment only)

main.py additions:

  • module-level _stop_event = threading.Event()
  • monitor_log()'s outer loop checks _stop_event and uses _stop_event.wait(5.0) instead of time.sleep(5) so Quit can interrupt within ~5s
  • run_tray() — pystray icon + daemon worker thread + Quit/Restart/Open log handlers
  • install_autostart() / uninstall_autostart() — pylnk3-backed shortcut at %APPDATA%/Microsoft/Windows/Start Menu/Programs/Startup
  • argparse dispatch at the entry point: --tray, --install-autostart, --uninstall-autostart, --quiet

Optional dependencies

pystray, Pillow, and pylnk3 are imported lazily inside the helpers — python main.py (the existing flow) keeps working with zero new deps. If a user passes --tray or --install-autostart without the extras installed, they get a clear pip install ... hint and exit code 1.

requirements.txt documents the optional install as a comment so the runtime baseline (psutil, pypresence) is byte-identical.

Backwards compatibility

  • No flag → identical behavior to current main.py (rpc_connect() + monitor_log())
  • Existing call sites untouched; the only mutation to existing logic is time.sleep(5)_stop_event.wait(5.0), which is functionally equivalent when no flags are set
  • No new files added; no new required dependencies

Test plan

  • Windows live-smoke: python main.py --tray, confirm menu shows, status flips waiting → running once a character logs in
  • Windows live-smoke: python main.py --install-autostart creates %APPDATA%/.../Startup/PathOfExile2DiscordRPC.lnk; reboot; tray launches without console
  • Windows live-smoke: python main.py --uninstall-autostart removes the shortcut and exits 0 (or 1 if the shortcut was absent)
  • python main.py (no flags) behaves identically to before this PR
  • python main.py --tray without pystray/Pillow exits 1 with the install hint
  • python main.py --install-autostart without pylnk3 exits 1 with the install hint

Notes for review

…ostart

Closes the README "Launch as background service when game starts" item.

main.py
- argparse-based dispatch at the entry point: --tray, --install-autostart,
  --uninstall-autostart, --quiet (silences console for tray/autostart launches).
- module-level threading.Event _stop_event; monitor_log()'s outer loop now
  checks it and uses _stop_event.wait(5.0) instead of time.sleep(5) so the
  tray Quit menu can interrupt the watcher cleanly within ~5s.
- run_tray() spins up a daemon worker that calls rpc_connect() + monitor_log(),
  then runs pystray.Icon on the main thread (Windows requirement). Quit menu
  sets _stop_event and stops the icon; tray status reflects waiting/running/error.
  Restart re-execs the current process with the same argv.
- install_autostart() / uninstall_autostart() write/remove a Windows Startup-
  folder shortcut at %APPDATA%/Microsoft/Windows/Start Menu/Programs/Startup
  via pylnk3.for_file(). The shortcut launches the .exe (frozen) or the
  current python interpreter + this script (source install) with --tray --quiet.
- pystray, PIL.Image, and pylnk3 are imported lazily inside the helpers so
  `python main.py` (the existing flow) keeps working without the extras.
  Helpful sys.exit() messages prompt the user to pip install when missing.

requirements.txt
- documents the new optional extras (pystray, Pillow, pylnk3) as a comment;
  required deps (psutil, pypresence) stay byte-identical.

Why
- README has had "Launch as background service when game starts" open since
  the project started. Tray + Startup shortcut is the lightest path that
  works on Windows without admin rights or Service-Control-Manager wiring.
- All optional dependencies are gated behind argparse flags + lazy imports,
  so installs that never use --tray or --install-autostart see zero impact.

How to use

    pip install pystray Pillow pylnk3
    python main.py --tray              # foreground tray icon
    python main.py --install-autostart # boot --tray on Windows login
    python main.py --uninstall-autostart
PrEvIeS added a commit to PrEvIeS/Path-Of-Exile-2-RPC that referenced this pull request May 5, 2026
…in EN/RU/UA

The 4-PR upstream campaign (panvex-b6p) is feature-complete on this stacked
branch. Updates the user-facing READMEs and CLAUDE.md to reflect the four
shipped capabilities:

- Official PoE2 client support (Steam + PathOfExile.exe)
- Owner auto-pin (party-mate disambiguation)
- AFK / DND status with small-image override + restore
- Background tray service + Windows Startup shortcut

README.md / README.ru.md / README.ua.md
- Add explicit Features bullets for all four capabilities.
- Flip the To-Do checklist (now 5/5 complete).
- RU/UA translations get the new "Run as a background service" section
  to match the English README that was added during PR-4.

CLAUDE.md
- Replace the four open-work items with checked-off equivalents and a
  pointer to the upstream draft PRs (ezbooz#6, ezbooz#7, ezbooz#8, ezbooz#9). Notes that the
  remaining work is the end-of-campaign Windows live-smoke pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant